package com.zhou.kotlin_car_data_list.utils

import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory

/**
 * </br>
 * Date: 2025/8/241
 * Created by:zhourui
 */
object RetrofitUtils {

    private var retrofit: Retrofit? = null

    fun getRetrofit(baseUrl: String): Retrofit {
        if (retrofit == null) {
            retrofit = Retrofit.Builder()
                .baseUrl(baseUrl)
                .addConverterFactory(GsonConverterFactory.create())
                .build()
        }
        return retrofit!!
    }

    fun <T> getApi(baseUrl: String, cls: Class<T>?): T {
        val retrofit = getRetrofit(baseUrl).create(cls)
        return retrofit
    }
}